package com.learn.training.multithread.chapter12.demo1;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;

public class Demo1 {
    public static void main(String[] args) throws InterruptedException {
        CustomerThread ct = new CustomerThread();
        //方法
//        Thread.startVirtualThread(ct);


        // 方法二：使用Thread.ofVirtual()创建虚拟线程
        // 创建不启动
//        System.out.println("Thread.ofVirtual() test running");
//        Thread unstarted = Thread.ofVirtual().unstarted(ct);
//        unstarted.start();

        // 创建直接启动
//        Thread.ofVirtual().start(ct);



        // 方法3：使用 ThreadFactory 创建虚拟线程
//        System.out.println("ThreadFactory test running");
//        ThreadFactory factory = Thread.ofVirtual().factory();
//        Thread vt = factory.newThread(ct);
//        vt.start();

        // 方法4：使用
        ExecutorService es = Executors.newVirtualThreadPerTaskExecutor();
        es.submit(ct);

        Thread.sleep(5000);
    }
}
